package com.ssy.lingxi.message.handler.exception;

import com.ssy.lingxi.common.exception.BusinessException;
import com.ssy.lingxi.common.response.Wrapper;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局自定义业务异常处理类
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/22
 */
@RestControllerAdvice
@Order(1)
public class BusinessExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public Wrapper<?> validationBodyException(HttpServletRequest request, BusinessException exception) {
        return Wrapper.fail(exception.getCode(), exception.getMessage());
    }
}
